package net.techwatch.gwt.mvp.client.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasKeyUpHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class MessageFormWidget extends Composite implements MessageForm.Display {
	
	private Button sendButton = new Button("Send");
	private TextBox nameField = new TextBox();
	
	public MessageFormWidget() { 
		final HorizontalPanel panel = new HorizontalPanel();
		nameField.setText("GWT User");

		// We can add style names to widgets
		sendButton.addStyleName("sendButton");

		// Add the nameField and sendButton to the RootPanel
		// Use RootPanel.get() to get the entire body element
		panel.add(nameField);
		panel.add(sendButton);

		// Focus the cursor on the name field when the app loads
		nameField.setFocus(true);
		nameField.selectAll();
		
		initWidget(panel);
	}

	public Widget getWidget() {
		return this;
	}
	
	@Override
	public HasValue<String> getNamedField() {
		return nameField;
	}

	@Override
	public HasKeyUpHandlers getNamedFieldHandlers() {
		return nameField;
	}

	@Override
	public HasClickHandlers getSendButton() {
		return sendButton;
	}

}
